/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.account.Key.AccountBy;
/*    */ import com.zimbra.common.account.Key.CalendarResourceBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.AccountServiceException;
/*    */ import com.zimbra.cs.account.CalendarResource;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mailbox.MailboxIndex;
/*    */ import com.zimbra.cs.mailbox.MailboxIndex.IndexStats;
/*    */ import com.zimbra.cs.mailbox.MailboxManager;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class GetIndexStats
/*    */   extends AdminDocumentHandler
/*    */ {
/* 40 */   private static final String[] TARGET_ACCOUNT_PATH = { "mbox", "id" };
/*    */   
/*    */ 
/*    */ 
/*    */   protected String[] getProxiedAccountPath()
/*    */   {
/* 46 */     return TARGET_ACCOUNT_PATH;
/*    */   }
/*    */   
/*    */ 
/*    */ 
/*    */ 
/*    */   public boolean domainAuthSufficient(Map<String, Object> context)
/*    */   {
/* 54 */     return true;
/*    */   }
/*    */   
/*    */ 
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 61 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/*    */     
/* 63 */     Element mreq = request.getElement("mbox");
/* 64 */     String accountId = mreq.getAttribute("id");
/*    */     
/* 66 */     Provisioning prov = Provisioning.getInstance();
/* 67 */     Account account = prov.get(Key.AccountBy.id, accountId, zsc.getAuthToken());
/* 68 */     if (account == null) {
/* 69 */       throw AccountServiceException.NO_SUCH_ACCOUNT(accountId);
/*    */     }
/*    */     
/* 72 */     if (account.isCalendarResource())
/*    */     {
/* 74 */       CalendarResource resource = prov.get(Key.CalendarResourceBy.id, account.getId());
/* 75 */       checkCalendarResourceRight(zsc, resource, Rights.Admin.R_reindexCalendarResourceMailbox);
/*    */     } else {
/* 77 */       checkAccountRight(zsc, account, Rights.Admin.R_reindexMailbox);
/*    */     }
/*    */     
/* 80 */     Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account, false);
/* 81 */     if (mbox == null) {
/* 82 */       throw ServiceException.FAILURE("mailbox not found for account " + accountId, null);
/*    */     }
/*    */     
/* 85 */     Element response = zsc.createElement(AdminConstants.GET_INDEX_STATS_RESPONSE);
/* 86 */     MailboxIndex.IndexStats stats = mbox.index.getIndexStats();
/* 87 */     Element statsElem = response.addElement("stats");
/* 88 */     statsElem.addAttribute("maxDocs", stats.getMaxDocs());
/* 89 */     statsElem.addAttribute("deletedDocs", stats.getNumDeletedDocs());
/* 90 */     return response;
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 95 */     relatedRights.add(Rights.Admin.R_reindexMailbox);
/* 96 */     relatedRights.add(Rights.Admin.R_reindexCalendarResourceMailbox);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetIndexStats.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */